package com.util;

import java.text.SimpleDateFormat;

public class StringUtil {
	
	public static void main(String[] args) {
		SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println(bartDateFormat.format(null));
	}

	/**
	 * 字符串转int
	 * @param s
	 * @return
	 * @throws Exception
	 */
	static public int string2Int(String s) throws Exception {
		int res = 0;
		try {
			res = Integer.valueOf(s);
		} catch (NumberFormatException e) {
			throw new Exception("int型格式错误");
		}
		return res;
	}

	/**
	 * 字符串转double
	 * @param s
	 * @return
	 * @throws Exception
	 */
	static public double string2Double(String s) throws Exception {
		double res = 0;
		try {
			res = Double.valueOf(s);
		} catch (NumberFormatException e) {
			throw new Exception("double型格式错误");
		}
		return res;
	}

	static public String valueOf(java.util.Date date) {
		if(date == null)
			return null;
		SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return bartDateFormat.format(date);
	}

}
